# ## Paley matrix of a finite field of characteristic $\ne 2$

from PyM import *

def paley_matrix(F):
    if characteristic(F)==2:
        return "paley_matrix error: the characteristic of F must not be 2"
    q = cardinal(F)
    def x(j): return element(j,F)
    def chi(a): return legendre(a,F)
    return matrix([[chi(x(i)-x(j)) for j in range(q)] for i in range(q)])

F = Zn(5)
show(paley_matrix(F))

F = Zn(7)
show(paley_matrix(F))